package com.caiyouxi.finance.service.impl;

import com.caiyouxi.common.bean.QueryParams;
import com.caiyouxi.common.bean.ResData;
import com.caiyouxi.common.cache.RedisService;
import com.caiyouxi.common.service.BaseService;
import com.caiyouxi.finance.mapper.CouponBatchMapper;
import com.caiyouxi.finance.model.CouponBatch;
import com.caiyouxi.finance.service.CouponBatchServices;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;


@Service
@Transactional
public class CouponBatchServicesImpl extends BaseService implements CouponBatchServices {
    @Autowired
    private CouponBatchMapper mapper;
    @Autowired
    private RedisService redisService;

    @Override
    public ResData select_coupon_batch(CouponBatch bean) {
        return success(mapper.select_coupon_batch(bean.getId()));
    }

    @Override
    public ResData add_coupon_batch(CouponBatch bean) {
        return success(mapper.add_coupon_batch(bean));
    }

    @Override
    public ResData update_coupon_batch(CouponBatch bean) {
        return success(mapper.update_coupon_batch(bean));
    }

    @Override
    public ResData delete_coupon_batch(CouponBatch bean) {
        return success(mapper.delete_coupon_batch(bean));
    }

    @Override
    public ResData coupon_batch_list(CouponBatch bean) {
        QueryParams pageList = new QueryParams();
        if(bean.getPage_size() == 0){
            bean.setPage_size(Integer.parseInt(redisService.get("sys.pagesize").toString()));
        }
        pageList.setPage(bean.getPage());
        pageList.setList(mapper.coupon_batch_list(bean));
        pageList.setTotal(mapper.coupon_batch_counts(bean));
        return success(pageList);
    }

}
